//
//  StatusCellTableViewCell.swift
//  sina
//
//  Created by DXapple on 15/11/16.
//  Copyright © 2015年 sqlite. All rights reserved.
//

import UIKit
import SnapKit
let StatusCellMargin: CGFloat = 12
let StatusCellIconWitdth: CGFloat = 35

class StatusCellTableViewCell: UITableViewCell {
    var bottomConstaints: Constraint?
    var status: Status? {
        didSet{
        originalView.status = status
            //z转发微博
            self.bottomConstaints?.uninstall()
            if let re = status?.retweeted_status {
            reweetedView.retweetedStatus = re
                //s设置显示
                reweetedView.hidden = false
                BottomView.snp_updateConstraints { (make) -> Void in
                    self.bottomConstaints = make.top.equalTo(reweetedView.snp_bottom).constraint

                }
            } else{reweetedView.hidden = true
                BottomView.snp_updateConstraints { (make) -> Void in
                    self.bottomConstaints = make.top.equalTo(originalView.snp_bottom).constraint
                    
                }

            
            }
            
        }
    }
    
    override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        setupUI()
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    
    private func setupUI() {
        contentView.addSubview(originalView)
        contentView.addSubview(BottomView)
        contentView.addSubview(reweetedView)
        //        originalView.backgroundColor = UIColor.redColor()
        
        originalView.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(contentView.snp_top)
            make.left.equalTo(contentView.snp_left)
            make.right.equalTo(contentView.snp_right)
//            make.height.equalTo(50)
    
        }
        reweetedView.snp_updateConstraints { (make) -> Void in
            make.top.equalTo(originalView.snp_bottom)
            make.left.equalTo(originalView.snp_left)
            make.right.equalTo(originalView.snp_right)
        }
        
        
        
        BottomView.snp_makeConstraints { (make) -> Void in
//            BottomView.backgroundColor = UIColor.redColor()
            self.bottomConstaints = make.top.equalTo(reweetedView.snp_bottom).constraint
            make.left.equalTo(contentView.snp_left)
            make.right.equalTo(contentView.snp_right)
            make.height.equalTo(40)
        }
                
        contentView.snp_makeConstraints { (make) -> Void in
            make.bottom.equalTo(BottomView.snp_bottom)
            make.top.equalTo(self.snp_top)
            make.left.equalTo(self.snp_left)
            make.right.equalTo(self.snp_right)
            
            
            
            
            
            
            
        }
    
    }

    
    
    private lazy var BottomView: StatusCellBottomView = StatusCellBottomView()

    //懒加载控件
    private lazy var originalView: StatusOriginalView = StatusOriginalView()
    private lazy var reweetedView: ReweetedStatusView = ReweetedStatusView()

   

    
}
